<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<title>斗地主测试</title>
<script src="/socket.io.js"></script>
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/socket.io/4.7.2/socket.io.js"></script> -->
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script>
    $(function(){
        let userId,currentRoomId,gameType ="PT2_1201";
        // socket = io("123.57.129.108:3080",{debugger:true});
        // socket = io("ws://10.1.11.196:3080");
        // socket = io("sws.dev777.cc");
        socket = io("101.36.117.183:3061");
        // socket = io("dws.dragonplay.top");
        socket.on('connect', function(){
            console.log('connect a socket client');
           
        });
        // let startUser = 1;
        // var interval = setInterval(()=> {
        //     socket.emit("open", {userId:startUser++})
        //     console.log("----startUser----:"+startUser)
        //     if(startUser>300){
        //         clearInterval(interval)
        //     }
        // }, 2000)
        
        $("#send").click(function(){
            userId = $("#userId").val();
            // socket.emit("open", {userId,token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsImdhbWVJZCI6IlBUMl8xMjAxIiwidXNlcm5hbWUiOiJ6aGFuZ3NhbjIiLCJpYXQiOjE3MDkwMDgxNDksImV4cCI6MTcwOTA5NDU0OX0.DpQYe6EdXK5zTjW2iF5qMA6xI4Gm9Tqxe6rv6mxEAFI"})
            socket.emit("open", {userId,token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjYsImdhbWVJZCI6IlBUMl8xMjAxIiwidXNlcm5hbWUiOiIxMDA2NTQzNDkiLCJpYXQiOjE3MDkwMTI2MzYsImV4cCI6MTcwOTA5OTAzNn0.bdYBwRFEpfZVjraYrGQIA4HtFRwDhOSOCfH5Jc_aPmQ"})
        })
        //出牌
        $("#chupaiBtn").click(function(){
            let poker = $("#poker").val();
            socket.emit("game_chupai", {userId, roomId:currentRoomId,pais:[+poker],gameType})
        })
        //加倍请求
        $("#multiBtn").click(function(){
            socket.emit("game_double", {userId, roomId:currentRoomId,gameType,multi:3})
        })
        //同意加倍
        $("#agreeBtn").click(function(){
            socket.emit("game_agree_double", {userId, roomId:currentRoomId,gameType})
        })
        //放弃
        $("#giveupBtn").click(function(){
            console.log("------------currentRoomId-------------;"+currentRoomId)
            socket.emit("game_giveup", {userId, roomId:currentRoomId,gameType})
        })
        //继续游戏
        $("#continueBtn").click(function(){
            socket.emit("game_call", {userId, roomId:currentRoomId,gameType,state:1})
        })

        //放弃继续游戏
        $("#continueGiveupBtn").click(function(){
            console.log("------------currentRoomId-------------;"+currentRoomId)
            socket.emit("game_call", {userId, roomId:currentRoomId,gameType,state:2})
        })
        //放弃继续游戏
        $("#userInfo").click(function(){
            console.log("------------userInfo-------------;"+currentRoomId)
            socket.emit("user_info", {token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjYsImdhbWVJZCI6IlBUMl8xMjAxIiwidXNlcm5hbWUiOiIxMDA2NTQzNDkiLCJpYXQiOjE3MDkwMTI2MzYsImV4cCI6MTcwOTA5OTAzNn0.bdYBwRFEpfZVjraYrGQIA4HtFRwDhOSOCfH5Jc_aPmQ"})
        })
        //断线重连
        $("#connection").click(function(){
            socket.emit("game_connection", {"randomkey":"1705983464","roomId":"86549213","gameType":"PT2_1201","sign":"e5b870b9f2d40612b85f0ce8f88b4526","userId":1003})
        })
        // socket.on("open_result", function(data){
        //     console.log("-----------opern_result-------------------")
        //     console.log(data)
        // })
        socket.on("heart_result", function(data){
            console.log("-------------心跳返回------------")
            console.log(data)
        })
        socket.on("data", function(eventList){
            console.log("=================")
            console.log(eventList)
            socket.emit("heart", {})
            for(let event of eventList){
                let {data,eventName} = event;
                data = data || {};
                let {code, msg} = data;
                console.log("eventName:"+eventName+",code:"+code+",msg:"+msg)
                console.log(data)
                return;
                if(eventName == "open_result"){
                    let {gameId, roomId,index} = data || {};
                    if(!roomId){
                        socket.emit("room_match",{gameType,conf:{difen:1000,pc:2,st:"1"}})
                    }else{
                        socket.emit("room_enter", {roomId, gameType})
                    }
                }
                if(eventName == "room_match_result"){
                    let {roomId} = data;
                    currentRoomId = roomId;
                    socket.emit("room_enter", {roomId, gameType})
                }
                if(eventName == "room_enter_result"){
                    let {roomId,seats} = data;
                    currentRoomId = roomId;
                    let indexs = [0,1];
                    for(let {index} of seats){
                        let arrIndex = indexs.indexOf(index);
                        indexs.splice(arrIndex,1)
                    }
                    console.log("--------------")
                    console.log(indexs)
                    socket.emit("room_sitdown", {roomId, index:indexs[0], gameType})
                    //console.log("--------------发送消息--------------")
                    //socket.emit("chat_message", {"gameType":1001,"sign":"47ed6c46bad379f39947c7eb76f0a58b","msg":"{\"type\":1,\"content\":\"hello world\"}","cmdpush":"chat_message_push","randomkey":"1706692067","userId":10000,"roomId":"91180623"})
                    
                }
                if(eventName == "chat_message_push"){
                    console.log('---------------------chat_message_push------------')
                console.log(data)
                }
                if(eventName == "begin_push"){
                }
            }
        })
        //其他事件
        // socket.on("begin_push", function(result){
        //     console.log("begin_push")
        //     console.log(result)
        // })
        // socket.on("deal_poker_push", function(result){
        //     console.log("deal_poker_push")
        //     console.log(result)
        // })
        // socket.on("operate_push", function(result){
        //     console.log("operate_push")
        //     console.log(result)
        // })
        // socket.on("chupai_push", function(result){
        //     console.log("chupai_push")
        //     console.log(result)
        // })
        // socket.on("game_over_push", function(result){
        //     console.log("game_over_push")
        //     console.log(result)
        // })
        // socket.on("game_result", function(result){
        //     console.log("game_result")
        //     console.log(result)
        // })
        // socket.on("operate_push", function(result){
        //     console.log("operate_push")
        //     console.log(result)
        // })
    })
</script>
</head>
<body>
    <input type="text" id="userId" value="1001"><input type="button" value="open" id="send"></br>
    <input type="text" id="poker" value=""><input type="button" value="出牌" id="chupaiBtn"></br>
    <input type="button" value="加倍请求" id="multiBtn"></br>
    <input type="button" value="同意加倍" id="agreeBtn"></br>
    <input type="button" value="放弃" id="giveupBtn"></br>
    <input type="button" value="继续游戏" id="continueBtn">
    <input type="button" value="放弃游戏" id="continueGiveupBtn"></br>
    <input type="button" value="断线重连" id="connection"></br>
    <input type="button" value="用户信息" id="userInfo"></br>
    <br/>
    <br/>
    <textarea style="width: 400px;height:200px;">

    </textarea>
</body>
</html>